package com.sbr.seb.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sbr.seb.entity.TomcatApplication;
import com.sbr.seb.entity.server.Tomcat;
import com.sbr.seb.service.TomcatManagerService;
import com.sbr.seb.service.impl.TomcatManagerServiceImpl;



public class TomcatServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		Tomcat tomcat = new Tomcat();
		tomcat.setHost(request.getParameter("host"));
		tomcat.setPort(request.getParameter("port"));
		
		
		TomcatManagerService tomcatManagerService = new TomcatManagerServiceImpl();
		
		Collection<TomcatApplication> applicationList = tomcatManagerService.getApplicationsList(tomcat);


		request.setAttribute("applicationList", applicationList);
		request.getRequestDispatcher("managerList.jsp").forward(request,response);

	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}


}
